'use strict';
// 实例化数据库的操作
const db = uniCloud.database();
// 创建数据库的连接
const connect = db.collection("user");
// 取指令
const dbCmd = db.command;
// 返回的结果内容
let res = null;
exports.main = async (e, context) => {
	switch (e.method) {
		// 查找用户
		case "findUser":
			switch (e.data.id) {
				case "weixin":
					res = await connect.where({
						"weixin": e.data.openid,
					}).get();
					break;
				case "qq":
					res = await connect.where({
						"qq": e.data.openid,
					}).get();
					break;
				default:
					res = await connect.where({
						"sinaweibo": e.data.openid,
					}).get();
					break;
			};
			break;
			// 手机验证码登录
		case "codeLogin":
			res = await connect.where({
				username: e.username,
				password: e.password
			}).get();
			break;
		case "accountPasswordLogin":
			// 注册
			res = await connect.add(e.data);
			break;
	};
	return res;
};
